import React, { Component } from 'react'
import {Menu} from "antd"
import {
    DesktopOutlined,
    PieChartOutlined,
    FileOutlined,
    TeamOutlined,
    UserOutlined,
} from '@ant-design/icons';
import { routerList } from '../../utils/routerList';
import mobxdata from "../../mobx/data"
import {observer} from "mobx-react"
import { hashHistory } from '../../utils';
const { SubMenu } = Menu;

@observer
export default class MyMenu extends Component {
    itemMenuClick=({item,key})=>{
        // console.log(item,key);
        this.props.history.push(key)
    }
    renderItemMenu=(routerList)=>{
        const {userinfo} = mobxdata  // 获取权限信息
        return routerList.map((l,i)=>{
            if(l.children){
                if(userinfo.role*1<l.premisssion*1){
                    return null
                }else{
                    return(
                        <SubMenu key={l.path} icon={l.icon} title={l.title}>
                            {this.renderItemMenu(l.children)}
                        </SubMenu>
                    )
                }
            }else{
                if(userinfo.role*1<l.premisssion*1){
                    return null
                }else{
                    return (
                        <Menu.Item key={l.path} icon={l.icon}>
                            {l.title}
                        </Menu.Item>
                    )
                }
            }
        })
    }
    render() {
        return (
            <Menu theme="dark" defaultSelectedKeys={['1']} mode="inline" onClick={this.itemMenuClick}>
                {
                    this.renderItemMenu(routerList)
                }
            </Menu>
        )
    }
}
